//
//  GlassMaterial.cpp
//  RayTracer
//
//  Created by 俞云康 on 3/25/16.
//  Copyright © 2016 yushroom. All rights reserved.
//

#include "GlassMaterial.hpp"
#include "Params.hpp"

shared_ptr<Material> GlassMaterial::create(const Params& params) {
    Color Kr = params.getColor("Kr");
    Color Kt = params.getColor("Kt");
    float index = params.getFloat("IOR");
    return make_shared<GlassMaterial>(Kr, Kt, index);
}

shared_ptr<BSDF> GlassMaterial::getBSDF(const HitInfo& hit) const  {
    auto bsdf = std::make_shared<BSDF>(hit, hit.normal);
    float ior = index;
    bsdf->add(new SpecularReflection(&hit, Kr, std::make_shared<FresnelDialectric>(1.0f, ior)));
    bsdf->add(new SpecularTransmission(&hit, Kt, 1.f, ior));
    return bsdf;
}